package cn.simple.manager.configuration;

import cn.simple.manager.scheduling.WechatNewsTaskSpider;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import weixin.popular.support.TokenManager;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

//@Configuration
@ConfigurationProperties("wechat")
@Data
public class WechatConfiguration {

    private String appid;
    private String secret;

    @Bean
    public WechatNewsTaskSpider wechatNewsTaskSpider(){

        return new WechatNewsTaskSpider();
    }
    @PostConstruct
    private void  wechatTokenInit(){
        TokenManager.setDaemon(false);
        TokenManager.init(appid,secret);
    }
    @PreDestroy
    public void wechatTokenDestroy(){
        TokenManager.destroyed();
    }
}
